using System.Web.Mvc;
using FrontEnd.Application.ContentService;
using System.Diagnostics.Contracts;
using FrontEnd.Models;

namespace FrontEnd.Controllers
{
    public class ProposalsController : Controller
    {
		public ProposalsController(IContentService contentService)
        {
            CodeContract.RequiresAlways(contentService != null);
            this.ContentService = contentService;
        }

        public IContentService ContentService
        {
            get;
            private set;
        }

		public ViewResult Index()
		{
			ProposalsModel model =
				new ProposalsModel
				{
					ProposalsPage = new ListSinglePage<ProposalInfo>(this.ContentService.EnumerateAvailableProposals(), 1, 1, 1)
				};

			return View(model);
		}

		public ActionResult IncrementUserAdds(string proposalName)
        {
            int actualUserAdds = this.ContentService.IncrementProposalUserAdds(proposalName);

            return Json(new UserAddsResult { IsSuccess = true, ActualUserAdds = actualUserAdds });
        }
    }
}
